package com.vpen.blog.utils;


import org.springframework.web.multipart.MultipartFile;

import java.io.*;
import java.util.HashMap;

/**
 * -@Version 1.0
 * -@Author:Vpen
 * -@Date:2021/7/12 21:31
 * -@Content:
 */
public class FileUtils {


    /**
     * 作者:Vpen
     * 描述:解析上传的md文件
     * */
    public static HashMap<String, Object> parseArticleFile(MultipartFile file) throws IOException {
        InputStream inputStream = file.getInputStream();// 获取文件输入字节流
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));// 包装成字符流
        String strTemp;
        HashMap<String, Object> map = new HashMap<>();
        String text = "";
        String title = reader.readLine();// 第一行当中标题
        // 之后是文章内容
        while ((strTemp = reader.readLine())!=null){
            text = text + strTemp+"\n";
        }

        map.put("content",text);
        map.put("title",title);

        return map;
    }

    public static String parseMd() throws IOException {
        File file = new File("src/第一次使用Typora.md");
        BufferedReader reader = new BufferedReader(new FileReader(file));
        String strTemp;
        while ((strTemp = reader.readLine()) != null) {
            System.out.println(strTemp);
        }
        return null;
    }

}
